package main

import "fmt"

func longestNiceSubstring(s string) string {
	lens := len(s)
	res := ""
	for i := 0; i < lens-1; i++ {
		for j := i + 1; j < lens; j++ {
			subStr := s[i : j+1]
			if check(subStr) && len(res) < len(subStr) {
				res = subStr
			}
		}
	}
	return res
}

func check(s string) bool {
	lower, uper := 0, 0
	for _, v := range s {
		if 'a' <= v && v <= 'z' {
			lower |= 1 << (v - 'a')
		} else {
			uper |= 1 << (v - 'A')
		}
	}
	return lower == uper
}

func main() {
	fmt.Println(longestNiceSubstring("HkhBubUYy"))
	fmt.Println(longestNiceSubstring("c"))

}
